package com.example.edu_sugar.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.edu_sugar.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
public class SugarController {

    @Autowired
    CourseService courseService;

    @RequestMapping("/sugar/comment")
    public String markScore(Integer date){
        // 如果前端没有传入日期，就自动今天
        if (date == null){
            date = Integer.valueOf(new SimpleDateFormat("yyyyMMdd").format(new Date()));
        }

        Long markScore = courseService.markScore(date);

        JSONObject result = new JSONObject();
        result.put("status",0);
        result.put("msg","");
        JSONObject comment = new JSONObject();
//        comment.put("name",)
        result.put("data",comment);
        return result.toJSONString();

    }
}
